﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Data
{
    public class ForecastPost
    {
        /// <summary>
        /// 主键
        /// </summary>
        private readonly string primaryKey = "id";
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long Add(Model.ForecastPost model)
        {
            return new DataAccess().Add<Model.ForecastPost>(model, primaryKey);
        }
        public Model.ForecastPost GetModelBysql(string sql)
        {
            return new DataAccess().Get<Model.ForecastPost>(sql);
        }
        public List<Model.ForecastPost> GetPageListWhere(int PageIndex, int PageSize, string sql, out int totalCount)
        {
            totalCount = new DataAccess().GetCount<Model.ForecastPost>(primaryKey, sql);
            return new DataAccess().GetPage_List<Model.ForecastPost>(PageIndex, PageSize, primaryKey, "addtime desc", sql);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.ForecastPost model)
        {
            return new DataAccess().Update<Model.ForecastPost>(model, primaryKey);
        }

        public Model.ForecastPost GetModelByuser_id(long id)
        {
            return new DataAccess().Get<Model.ForecastPost>(id, "id");
        }
        public string GetSqlWhere(long newsclassid)
        {
            StringBuilder sqlWhere = new StringBuilder();

            sqlWhere.Append(" 1>0");

            if (newsclassid > 0)
            {
                sqlWhere.Append(" and LotteryType =" + newsclassid);
            }
            return sqlWhere.ToString();
        }

        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.ForecastPost GetModel(long Id)
        {
            return new DataAccess().Get<Model.ForecastPost>(Id, primaryKey);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(long Id)
        {
            return new DataAccess().Delete<Model.ForecastPost>(Id, primaryKey);
        }
    }
}
                        